package cn.itcast.www.junitTest;

import java.awt.Button;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class GoodSetSize extends Frame {

	TextArea status;
	public GoodSetSize(){
		super("Good Set Size");
		setLayout(new GridLayout(2,0,2,2));
		Panel p = new Panel();
		CustomButton button = new CustomButton("Press Me");
		p.add(button);
		add(p);
		status = new TextArea(3, 50);
		//��ʾ��ʱ��ť�Ĵ�С����Ϊ100,100
		status.append("Button size before display:" + button.getSize()+"\n");
		add(status);
		addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent we){
				System.exit(1);
			}
		});
		setLocation(100, 100);
		pack();
		setVisible(true);
		//��ʾ��ʱ��ť�Ĵ�С��ԭΪ66,23��С��
		status.append("Button size after display:" + button.getSize());
	}
	public static void main(String[] args) {
		new GoodSetSize();

	}
	
}

class CustomButton extends Button{
	public CustomButton(String title){
		super(title);
		setSize(100, 100);
	}
	//Ϊ���ܹ���ȷ��ʾ���õĴ�С����Ҫ��д������������

	@Override
	public Dimension getMinimumSize() {
		return new Dimension(100, 100);
	}

	@Override
	public Dimension getPreferredSize() {
		return this.getMinimumSize();
	}
	
}